const express=require('express');
const cors = require('cors');
const bodyParser=require('body-parser');
const entryRouter = require('./router/entry')
const db=require('./db/index');
const app = express();
app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended:true}));
app.use(cors());
app.use(entryRouter);
app.use('/',async(req,res,next)=>{
    try{
        await db;

        next();
    }catch(e){
        console.log(e);
        res.send('服务器和数据库连接失败')

    }
        
   
})

app.listen(3000,err=>{
    if(!err){
        console.log('服务器启动成功')
    }else{
        console.log(err);
    }
})